import 'package:flutter/material.dart';
import '../login_screen.dart';

class SettingsTab extends StatelessWidget {
  const SettingsTab({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('设置'),
        elevation: 0,
      ),
      body: ListView(
        children: [
          // 用户信息卡片
          Card(
            margin: const EdgeInsets.all(16),
            child: ListTile(
              contentPadding: const EdgeInsets.all(16),
              leading: CircleAvatar(
                radius: 30,
                backgroundColor: Colors.grey[200],
                child: const Icon(Icons.person, size: 32),
              ),
              title: const Text(
                '用户名',
                style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
              ),
              subtitle: const Text('点击修改个人信息'),
              onTap: () {
                // TODO: 跳转到个人信息编辑页面
              },
            ),
          ),
          const Divider(height: 1),
          // 基本设置
          _buildSectionHeader('基本设置'),
          ListTile(
            leading: const Icon(Icons.edit),
            title: const Text('修改用户名'),
            trailing: const Icon(Icons.chevron_right),
            onTap: () {
              // TODO: 实现修改用户名功能
            },
          ),
          ListTile(
            leading: const Icon(Icons.image),
            title: const Text('修改头像'),
            trailing: const Icon(Icons.chevron_right),
            onTap: () {
              // TODO: 实现修改头像功能
            },
          ),
          ListTile(
            leading: const Icon(Icons.lock),
            title: const Text('修改密码'),
            trailing: const Icon(Icons.chevron_right),
            onTap: () {
              // TODO: 实现修改密码功能
            },
          ),
          const Divider(height: 1),
          // 通知设置
          _buildSectionHeader('通知设置'),
          SwitchListTile(
            secondary: const Icon(Icons.notifications),
            title: const Text('推送通知'),
            subtitle: const Text('接收新消息和活动提醒'),
            value: true,
            onChanged: (bool value) {
              // TODO: 实现推送通知开关
            },
          ),
          const Divider(height: 1),
          // 其他设置
          _buildSectionHeader('其他设置'),
          ListTile(
            leading: const Icon(Icons.info),
            title: const Text('关于我们'),
            trailing: const Icon(Icons.chevron_right),
            onTap: () {
              // TODO: 显示关于页面
            },
          ),
          ListTile(
            leading: const Icon(Icons.help),
            title: const Text('帮助与反馈'),
            trailing: const Icon(Icons.chevron_right),
            onTap: () {
              // TODO: 显示帮助页面
            },
          ),
          const Divider(height: 1),
          // 退出登录
          Padding(
            padding: const EdgeInsets.all(16),
            child: ElevatedButton(
              onPressed: () {
                showDialog(
                  context: context,
                  builder: (context) => AlertDialog(
                    title: const Text('退出登录'),
                    content: const Text('确定要退出登录吗？'),
                    actions: [
                      TextButton(
                        onPressed: () => Navigator.pop(context),
                        child: const Text('取消'),
                      ),
                      TextButton(
                        onPressed: () {
                          Navigator.pop(context);
                          Navigator.pushReplacement(
                            context,
                            MaterialPageRoute(builder: (context) => const LoginScreen()),
                          );
                        },
                        child: const Text('确定'),
                      ),
                    ],
                  ),
                );
              },
              style: ElevatedButton.styleFrom(
                backgroundColor: Colors.red,
                padding: const EdgeInsets.symmetric(vertical: 12),
              ),
              child: const Text('退出登录'),
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildSectionHeader(String title) {
    return Padding(
      padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),
      child: Text(
        title,
        style: const TextStyle(
          fontSize: 16,
          fontWeight: FontWeight.bold,
          color: Colors.grey,
        ),
      ),
    );
  }
}